'''
Author: xialang333@gmail.com
Date: 2024-07-11 15:19:52
LastEditTime: 2024-08-02 15:20:51
'''
import os
from application.settings import BASE_DIR

# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # other app
    # 'channels',#websocket
    'django_comment_migrate',
    'rest_framework',
    'django_filters',
    'django_apscheduler',
    'django_q',
    'corsheaders',  # 允许跨域
    'drf_yasg',  # 在线接口文档
    'captcha',  # 验证码
    # myown app
    'mysystem',
    # custom app
    'apps.lyusers',
    'apps.lywebsocket',
    'apps.crond',
    'apps.software',
]
# ================================================= #
# ************** 数据库 配置  ************** #
# ================================================= #

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
# sqlite3
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'xops.db',
    }
}

# ================================================= #
# ************** redis 配置  ************** #
# ================================================= #

REDIS_PASSWORD = ''
REDIS_HOST = '10.0.172.57'
REDIS_PORT = '6379'
REDIS_URL = f'redis://:{REDIS_PASSWORD or ""}@{REDIS_HOST}:{REDIS_PORT}'

Q_CLUSTER = {
    'name': 'xops',
    'workers': 4,
    'recycle': 500,
    'timeout': 60,
    'compress': True,
    'cpu_affinity': 1,
    'save_limit': 250,
    'queue_limit': 500,
    'label': 'Django Q',
    'redis': REDIS_URL
}
# ================================================= #
# ************** 服务器基本 配置  ************** #
# ================================================= #
DEBUG = True  # 是否调试模式
IS_DEMO = False  # 是否演示模式（演示模式只能查看无法保存、编辑、删除、新增）
IS_SINGLE_TOKEN = False  # 是否只允许单用户单一地点登录(只有一个人在线上)(默认多地点登录),只针对后台用户生效
ALLOW_FRONTEND = True  # 是否关闭前端API访问
FRONTEND_API_LIST = []  # 微服务前端接口前缀
DOMAIN_HOST = "http://127.0.0.1:8000"
EXEC_LOG_PATH = os.path.join(BASE_DIR, 'logs', 'lybbnexec.log')
TEMP_EXEC_PATH = os.path.join(BASE_DIR, 'logs')

# ================================================= #
# **************** 验证码配置  ******************* #
# ================================================= #
CAPTCHA_STATE = False
CAPTCHA_IMAGE_SIZE = (160, 60)  # 设置 captcha 图片大小
CAPTCHA_LENGTH = 4  # 字符个数
CAPTCHA_TIMEOUT = 1  # 超时(minutes)
CAPTCHA_OUTPUT_FORMAT = '%(image)s %(text_field)s %(hidden_field)s '
CAPTCHA_FONT_SIZE = 42  # 字体大小
CAPTCHA_FOREGROUND_COLOR = '#409eff'  # 前景色
CAPTCHA_BACKGROUND_COLOR = '#FFFFFF'  # 背景色
CAPTCHA_NOISE_FUNCTIONS = (
    'captcha.helpers.noise_arcs',  # 线
    # 'captcha.helpers.noise_dots', # 点
)
# CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.random_char_challenge' #字母验证码
CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'  # 加减乘除验证码


TABLE_PREFIX = "tb_"